<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员列表</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="__CSS__/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__CSS__/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__CSS__/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="__CSS__/animate.min.css" rel="stylesheet">
    <link href="__CSS__/style.min.css?v=4.1.0" rel="stylesheet">
    <link href="__CSS__/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <style>
        #recharge {
            margin: 20px;
        }
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>会员列表</h5>
        </div>
        <div class="ibox-content">
            <form role="form" method="post" class="form-inline pull-left">
                <div class="content clearfix m-b">
                    <div class="form-group">
                        <label>注册新会员赠送的金额：</label>
                        <input type="text" class="form-control" id="money" value="{$config.value}" style="width: 50px" {$config.status? 'disabled':''}>￥
                    </div>
                    <div>
                        功能状态：<strong id="status">{$config.status? "开启":"关闭"}</strong>
                        <button class="btn btn-primary" type="button" style="margin-top:5px" id="change-config" data-status="{$config.status}"><strong>{$config.status? "关闭":"开启"}</strong>
                        </button>
                    </div>
                </div>
            </form>
            <!--搜索框开始-->
            <form id='commentForm' role="form" method="post" class="form-inline pull-right">
                <div class="content clearfix m-b">
                    <div class="form-group">
                        <label>手机号：</label>
                        <input type="text" class="form-control" id="username" name="user_name" style="width: 130px">
                    </div>
                    <div class="form-group">
                        <label>状态：</label>
                        <select id="status" class="form-control">
                            <option value="">请选择</option>
                            <option value="0">未验证</option>
                            <option value="2">待验证</option>
                            <option value="1">已验证</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <button class="btn btn-primary" type="button" style="margin-top:5px" id="search"><strong>搜 索</strong>
                        </button>
                    </div>
                </div>
            </form>
            <!--搜索框结束-->
            <div class="example-wrap">
                <div class="example">
                    <table id="cusTable">
                        <thead>
                        <th data-field="memb_id">会员ID</th>
                        <th data-field="memb_name">会员名</th>
                        <th data-field="memb_phone">手机号</th>
                        <th data-field="memb_point">积分</th>
                        <th data-field="memb_balance">账户余额</th>
                        <th data-field="is_truth">实名认证</th>
                        <th data-field="status">状态</th>
                        <th data-field="operate">操作</th>
                        </thead>
                    </table>
                </div>
            </div>
            <!-- End Example Pagination -->
        </div>
    </div>
</div>
<!-- End Panel Other -->
<div style="overflow: hidden; height: 0;">
    <div class="form" id="recharge">
        <div class="form-group" style="width: 200px">
            <label>说明：</label>
            <div class="input-group">
                <input type="text" class="form-control" id="desc" name="desc" placeholder="请填写描述" required aria-required="true">
            </div>
        </div>
        <div class="form-group">
            <label>金额：</label>
            <div class="input-group" style="width: 200px">
                <div class="input-group-addon">￥</div>
                <input type="text" class="form-control" id="value" name="value" placeholder="请输入整数的金额" required aria-required="true">
            </div>
        </div>
    </div>
</div>
<script src="__JS__/jquery.min.js?v=2.1.4"></script>
<script src="__JS__/bootstrap.min.js?v=3.3.6"></script>
<script src="__JS__/content.min.js?v=1.0.0"></script>
<script src="__JS__/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="__JS__/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="__JS__/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="__JS__/plugins/suggest/bootstrap-suggest.min.js"></script>
<script src="/static/laydate/laydate.js"></script>
<script src="__JS__/plugins/sweetalert/sweetalert.min.js"></script>
<script src="/static/layer/layer.js"></script>
<script type="text/javascript">
    function initTable() {
        //先销毁表格
        $('#cusTable').bootstrapTable('destroy');
        //初始化表格,动态从服务器加载数据
        $("#cusTable").bootstrapTable({
            method: "get",  //使用get请求到服务器获取数据
            url: "./index", //获取数据的地址
            striped: true,  //表格显示条纹
            pagination: true, //启动分页
            pageSize: 10,  //每页显示的记录数
            pageNumber:1, //当前第几页
            pageList: [5, 10, 15, 20, 25],  //记录数可选列表
            sidePagination: "server", //表示服务端请求
            paginationFirstText: "首页",
            paginationPreText: "上一页",
            paginationNextText: "下一页",
            paginationLastText: "尾页",
            queryParamsType : "undefined",
            queryParams: function queryParams(params) {   //设置查询参数
                var param = {
                    pageNumber: params.pageNumber,
                    pageSize: params.pageSize,
                    searchText:$('#username').val(),
                    status:$('#status').val()
                };
                return param;
            },
            onLoadSuccess: function(res){  //加载成功时执行
                if(111 == res.code){
                    window.location.reload();
                }
                layer.msg("加载成功", {time : 1000});
            },
            onLoadError: function(){  //加载失败时执行
                layer.msg("加载数据失败");
            }
        });
    }

    $(document).ready(function () {
        //调用函数，初始化表格
        initTable();

        //当点击查询按钮的时候执行
        $("#search").bind("click", initTable);

        $('#change-config').bind('click', function(){
            layer.confirm('确认修改?', {icon: 3, title:'提示'}, function(index){
            //do something
            var money = $('#money').val();
            var status = $('#change-config').attr('data-status');
            console.log(status)
            $.post("{:url('member/changeConfig')}",{status: status, money: money}, function(res){
                if(1 == res.code){
                    layer.alert(res.msg, {title: '友情提示', icon: 1, closeBtn: 0}, function(index){
                        layer.close(index)
                        $('#change-config').attr('data-status', res.data.status)
                        $('#change-config').text(res.data.btn)
                        if(res.data.status){
                            $('#status').text('开启')
                            $('#money').attr('disabled', 'disabled')
                        }else{
                            $('#status').text('关闭')
                            $('#money').removeAttr('disabled')
                        }
                    });
                }else{
                    layer.alert(res.msg, {title: '友情提示', icon: 2});
                }
            });

            layer.close(index);
        })
        })
    });

    function userDel(id){
        layer.confirm('确认删除此会员?', {icon: 3, title:'提示'}, function(index){
            //do something
            $.getJSON("{:url('member/delete')}", {'id' : id}, function(res){
                if(1 == res.code){
                    layer.alert(res.msg, {title: '友情提示', icon: 1, closeBtn: 0}, function(){
                        initTable();
                    });
                }else if(111 == res.code){
                    window.location.reload();
                }else{
                    layer.alert(res.msg, {title: '友情提示', icon: 2});
                }
            });

            layer.close(index);
        })

    }

    function recharge(id){
        layer.open({
            type: 1,
            title: '充值/消费',
            area: ['300px', '280px'],
            resize: false,
            move: false,
            content: $('#recharge'),
            btn: ['确定'],
            yes: function(index) {
                var desc = $('#desc').val()
                var value = $('#value').val()
                let inputReg = /^\d+|^-\d+$/
                if(!desc){
                    layer.alert('请填写描述')
                    return ;
                }
                if(!inputReg.test(value)) {
                    layer.alert('请输入正确的金额')
                    return ;
                }
                layer.close(index)
                var loader = layer.msg('加载中...', {icon: 16, shade: 0.3})
                $.post('{:url("member/recharge")}', {uid: id, desc: desc, value:value}, function(res){
                    layer.close(loader);
                    if(1 == res.code){
                        layer.alert(res.msg, {title: '友情提示', icon: 1, closeBtn: 0}, function(){
                            initTable();
                        });
                    }else if(111 == res.code){
                        window.location.reload();
                    }else{
                        layer.alert(res.msg, {title: '友情提示', icon: 2});
                    }
                })
            }
        })
    }
</script>
</body>
</html>
